#include "Config.h"
#include "Cfg.h"
#include "ConfigScript.h"
#include "wch/File.h"
#include "wch/StringTokenizer.h"
#include "Common/Atoi.h"
#include "Common/tinyxml.h"
#include "Server/ServerType.h"

using namespace wch;


Cfg cfg;

Cfg::Cfg()
: _sid(0), _tcpPort(0), _hallPort(0), _free(true)
{

}

bool Cfg::load( const std::string& file_ )
{
	_file = file_;
	ConfigScript script( this );
	script.doFile( _file.c_str() );
	return true;
}

void Cfg::setPlayer1Mjs(const char * mjs)
{
	StringTokenizer tokenizer(mjs, "|");
	for (size_t i = 0; i < tokenizer.count(); ++i)
	{
		_allotMjs[0].push_back(Atoi<UInt8>(tokenizer[i]));
	}
}

void Cfg::setPlayer2Mjs(const char * mjs)
{
	StringTokenizer tokenizer(mjs, "|");
	for (size_t i = 0; i < tokenizer.count(); ++i)
	{
		_allotMjs[1].push_back(Atoi<UInt8>(tokenizer[i]));
	}
}

void Cfg::setPlayer3Mjs(const char * mjs)
{
	StringTokenizer tokenizer(mjs, "|");
	for (size_t i = 0; i < tokenizer.count(); ++i)
	{
		_allotMjs[2].push_back(Atoi<UInt8>(tokenizer[i]));
	}
}

void Cfg::setPlayer4Mjs(const char * mjs)
{
	StringTokenizer tokenizer(mjs, "|");
	for (size_t i = 0; i < tokenizer.count(); ++i)
	{
		_allotMjs[3].push_back(Atoi<UInt8>(tokenizer[i]));
	}
}